<template>
	<view class="tabbar-container">
		<block>
			<view class="tabbar-item" v-for="(item,index) in tabbarList" :key="index"
				:class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
				<view class="item-top">
					<image :src="currentItem==item.id?item.selectedIconPath:item.iconPath"></image>
				</view>
				<view class="item-bottom" :class="[currentItem==item.id ? 'item-active' : '']">
					<text>{{item.text}}</text>
				</view>
			</view>
		</block>
 
	</view>
</template>
 
<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				currentItem: 0,
				"tabbarList": {
				    "color": "#666666",
				    "selectedColor": "#004095",
				    "borderStyle": "black",
				    "backgroundColor": "#ffffff",
					"custom": true,
				    "list": [
				    	{
				    		"pagePath": "pages/home/index",
				    		"iconPath": "/static/img/home/home_bar.png",
				    		"selectedIconPath": "/static/img/home/home_bar_select.png",
				    		"text": "Home"
				    	}, 
				    	{
				    		"pagePath": "pages/news/newsIndex",
				    		"iconPath": "/static/img/news/news_bar.png",
				    		"selectedIconPath": "/static/img/news/news_bar_select.png",
				    		"text": "Message"
				    	},
				    	{
				    		"pagePath": "pages/personal_center/index",
				    		"iconPath": "/static/img/personal_center/my_bar.png",
				    		"selectedIconPath": "/static/img/personal_center/my_bar_select.png",
				    		"text": "Mine"
				    	}
				    
				    ]
				}	
			};
		},
		mounted() {
			this.currentItem = this.currentPage;
			uni.hideTabBar();
		},
		methods: {
			changeItem(item) {
				let _this = this;
				//_this.currentItem = item.id;  
				uni.switchTab({
					url: item.path
				});
			}
		}
	}
</script>
<style>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}
 
	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100rpx;
		/* box-shadow: 0 0 5px #999; */
		border-top: 1px solid #4CD964;
		display: flex;
		align-items: center;
		padding: 5rpx 0;
		color: #999999;
		z-index: 1000;
	}
 
	.tabbar-container .tabbar-item {
		width: 20%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
	}
 
	.tabbar-container .item-active {
		color: #66CCFF;
	}
 
	.tabbar-container .center-item {
		display: block;
		position: relative;
	}
 
	.tabbar-container .tabbar-item .item-top {
		width: 70rpx;
		height: 70rpx;
		padding: 10rpx;
	}
 
	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 100rpx;
		height: 100rpx;
		position: absolute;
		top: -50rpx;
		left: calc(50% - 50rpx);
		border-radius: 50%;
		box-shadow: 0 0 5px #999;
		background-color: #ffffff;
	}
 
	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
	}
 
	.tabbar-container .tabbar-item .item-bottom {
		font-size: 28rpx;
		width: 100%;
	}
 
	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 5rpx;
	}
 
	/* 适配iphonex 有底部横条的 */
	@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {
		.tabbar-container {
			bottom: constant(safe-area-inset-bottom);
			bottom: env(safe-area-inset-bottom);
		}
	}
</style>